import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By as by
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.action_chains import ActionChains as mouse
import time
import re



class TestGql3:

    def test_1(self):
        s = Service(r"/Users/didi1/Desktop/chromedriver.exe")
        web = webdriver.Chrome(service=s)
        web.implicitly_wait(10)
        token = "k0cjjs8asx3ANv64N9NMf8pC8PWdrgl2yxtjelSIFp8czDtuxDAMBuG7TE0YPyVLtNimzx3ycB6NAiRIZezdF9p6Bt_FFEndtAljOunGLKRLkjEr6dFG3-Vq7Wgr76T3Vo8xiq-nkTw9Y7yQYLySZQyF14hoUVSNd9KLcZIXfz__v28nqZvxsay9e6kP65NEknfFUFSMLxLH-F7_PQAA__8="
        web.get("http://10.190.7.204:8080/wyc-webx/feature-pinche5.0/wyc-cpagregation/index.html#/main?token=" + token)
        web.maximize_window()
        time.sleep(7)

        # 打开活动页面
        if web.find_element(by.XPATH, "//*[@id='main']/div[2]/div[1]/div/div[2]/div/div/div[1]/div"):
            web.get_screenshot_as_file(r'/Users/didi1/Desktop/宫庆禄滴滴/ui自动化/弹窗截图.png')
            print("领券弹窗截图成功")
        time.sleep(3)
        web.find_element(by.XPATH, "//*[@id='main']/div[2]/div[1]/div/div[2]/div/div/div[2]").click()

        # 鼠标从第一关拖动游戏到最后一关
        source = web.find_element(by.XPATH,
                                  "//*[@id='main']/div[1]/div[2]/div/div[1]/div[3]/div[3]/div[1]/div/div[1]/div/img")
        target = web.find_element(by.XPATH,
                                  "//*[@id='main']/div[1]/div[2]/div/div[1]/div[3]/div[3]/div[1]/div/div[3]/div/img")
        action = mouse(web)
        action.drag_and_drop(source, target).perform()
        time.sleep(1)
        web.get_screenshot_as_file(r'/Users/didi1/Desktop/宫庆禄滴滴/ui自动化/游戏最后一关截图.png')
        print("游戏最后一关截图成功")
        target.click()
        l = web.find_element(by.XPATH, '/html/body/div[2]').text
        print(l)
        assert(l == "还未解锁喔～")

        # 点击开始游戏
        web.find_element(by.XPATH,'//*[@id="main"]/div[1]/div[2]/div/div[1]/div[3]/div[4]/img').click()
        p=web.current_url
        panduan=re.match("http.*game",p)
        if panduan:
            assert True
        else:
            assert False



if __name__=='__main__':
    pytest.main('[-vs]')

# 点开游戏玩

# time.sleep(10)
# web.quit()


# wb.find_element_by_id('kw').send_keys("防灾科技学院")
# wb.find_element_by_id('su').click()
# print(wb.find_element_by_id('1').text)
# wb.quit()